package com.augurit.gzcgwsp.csshlj.convert;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dozer.DozerBeanMapper;

import com.augurit.gzcgwsp.csshlj.entity.ShljYs;
import com.augurit.gzcgwsp.csshlj.form.ShljYsForm;
import com.augurit.gzcgwsp.sendNotice.exchangedatatofx.entity.ShljYsForFx;
import com.augurit.gzcgwsp.ywcmn.web.form.YwComQyxxForm;

/**
 * 道路挖掘 目前这个类，只有与方欣的数据交换用到
 * @author Administrator
 *
 */

public class YwHwShljysConvertor {
    public static ShljYsForm convertVoToForm(ShljYs entity) {
        if (entity == null) return null;
        ShljYsForm form = new DozerBeanMapper().map(entity, ShljYsForm.class); 
        form.setZsbh(entity.getFzh());
        return form;
    }
    
    public static void convertFormToQyxxForm(ShljYsForm form, YwComQyxxForm qyxxForm) {
        if (form == null) return;
        if (qyxxForm == null) qyxxForm = new YwComQyxxForm();

        new DozerBeanMapper().map(form, qyxxForm);
        if(StringUtils.isNotBlank(form.getQybh())){
        	qyxxForm.setId(Long.parseLong(form.getQybh()));
        }
    }

    public static void convertQyxxFormToForm(YwComQyxxForm qyxxForm, ShljYsForm form) {
        if (qyxxForm == null) return;
        if (form == null) form = new ShljYsForm();
        
        new DozerBeanMapper().map(qyxxForm, form);
        form.setQybh(qyxxForm.getId().toString());
    }
    
    public static void convertFormToVo(ShljYsForm form, ShljYs entity) {
        if (form == null) return;
        if (entity == null) entity = new ShljYs();
        
        new DozerBeanMapper().map(form, entity);
    }
    
    public static List<ShljYsForm> convertVoListToFormList(List<ShljYs> shljYsCzList) {
        if(shljYsCzList != null && shljYsCzList.size() > 0) {
            List<ShljYsForm> czFormList = new ArrayList();
            for(int i=0; i<shljYsCzList.size(); i++) {
            	czFormList.add(convertVoToForm(shljYsCzList.get(i)));
            }
            return czFormList;
        }
        return null;
    }
    
    public static List<ShljYs> convertFormListToVoList(List<ShljYsForm> shljYsFormList) {
        if(shljYsFormList != null && shljYsFormList.size() > 0) {
            List<ShljYs> shljYsList = new ArrayList();
            for(int i=0; i<shljYsFormList.size(); i++) {
                ShljYs ShljYs = new ShljYs();
                convertFormToVo(shljYsFormList.get(i), ShljYs);
                shljYsList.add(ShljYs);
            }
            return shljYsList;
        }
        return null;
    }
    
    public static void convertFormToShljYsForFx(ShljYsForm form, ShljYsForFx entity) {
        if (form == null) return;
        if (entity == null) entity = new ShljYsForFx();        
        new DozerBeanMapper().map(form, entity);
    }
}